#!/bin/bash

if [ $# = 1 ]
then
    configScript=$1
else
    echo No configure script path passed in!!!
    exit
fi

if [ -f $configScript ]
then
    source $configScript
else
    echo Invalid configure script path!!!
    exit
fi

# Const
implScript=InitLinuxImpl.sh

if [ -f $implScript ]
then
    source $implScript
else
    echo No $implScript in current folder!!!
    exit
fi

#########################
echo Now use normal USER!

### Configure emacs ###
flag=$(GetConfigVar IsConfigureEmacs $OS $VER)
AssertFunctionResult
if [ $flag = true ]
then
    ConfigureEmacs
fi

### Configure git ###
flag=$(GetConfigVar IsConfigureGit $OS $VER)
AssertFunctionResult
if [ $flag = true ]
then
    gitMail=$(GetConfigVar GitMail $OS $VER)
    AssertFunctionResult
    gitUser=$(GetConfigVar GitUser $OS $VER)
    AssertFunctionResult
    flag=$(GetConfigVar IsConfigureProxy $OS $VER)
    AssertFunctionResult
    ConfigureGit $gitMail "$gitUser" $flag
fi

### Create Home Folders ###
flag=$(GetConfigVar IsCreateFoldersInHome $OS $VER)
AssertFunctionResult
if [ $flag = true ]
then
    homeFolders=($(GetConfigArray HomeFolders $OS $VER))
    AssertFunctionResult
    for((i=0; i<${#homeFolders[@]}; i++))
    do
        CreateFolderInHome ${homeFolders[${i}]}
    done
fi

### Clean Home Folder ###
flag=$(GetConfigVar IsCleanHomeFolder $OS $VER)
AssertFunctionResult
if [ $flag = true ]
then
    homeFolders=($(GetConfigArray HomeFolders $OS $VER))
    AssertFunctionResult
    CleanHomeFolder ${homeFolders[@]}
fi
